package com.zzyl.controller;

import com.zzyl.BaseController.BaseController;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 访问角色管理
 */
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("角色分页")
    public ResponseResult page(@RequestBody UserDto userDto,
                               @PathVariable Integer pageNum,
                               @PathVariable Integer pageSize){
        userDto.setAvatar(String.valueOf(pageNum));
        userDto.setRemark(String.valueOf(pageSize));
        PageResponse<UserVo> pageResponse = userService.page(userDto,pageNum,pageSize);

        return success(pageResponse);
    }

    @PutMapping
    @ApiOperation("新增用户")
    public ResponseResult insert(@RequestBody UserDto userDto){
        userService.insert(userDto);
        return success();
    }

    @PatchMapping
    @ApiOperation("修改用户")
    public ResponseResult update(@RequestBody UserDto userDto){
        userService.update(userDto);
        return  success();
    }

    //TODO
    //@GetMapping("/current-user")
    @ApiOperation("当前用户")
    public ResponseResult currentUser(){

        return success();
    }

    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult isEnable(@PathVariable Long id , @PathVariable Integer status){
        userService.isEnable(id,status);
        return success();
    }

    @DeleteMapping("/remove/{userIds}")
    @ApiOperation("删除用户")
    public ResponseResult deleteById(@PathVariable Long userIds){
        userService.deleteById(userIds);
        return success();
    }

    @PostMapping("/list")
    @ApiOperation("查询所有用户")
    public ResponseResult list(@RequestBody UserDto userDto){
        List<UserVo> userVos = userService.list(userDto);
        return success(userVos);
    }

}
